import 'package:erp/main_state.dart';
import 'package:erp/res/colors.dart';
import 'package:erp/util/image_utils.dart';
import 'package:erp/widgets/my_app_bar.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

/// 我的资料
class MyProfile extends StatelessWidget {
  List<Widget> _buildLine(label, value, {bool? showDivider = true}) {
    return [
      Row(
        // crossAxisAlignment: CrossAxisAlignment.end,
        children: [
          Text(
            "${label}",
            style: TextStyle(color: Color(0XFF666666), fontSize: 30.sp, fontWeight: FontWeight.bold),
          ),
          Expanded(
            child: Container(
              height: 94.h,
            ),
          ),
          Text(
            "${value}",
            style: TextStyle(color: Color(0XFF666666), fontSize: 30.sp, fontWeight: FontWeight.normal),
          ),
        ],
      ),
      Offstage(
        offstage: !showDivider!,
        child: Divider(
          color: Color(0xFFEEEEEE),
          thickness: 2.w,
          height: 1.h,
        ),
      )
    ];
  }

  @override
  Widget build(BuildContext context) {
    var controller = Get.find<MainState>();
    var userInfo = controller.userInfo.value;
    return Container(
      /// banner
      decoration: BoxDecoration(
        image: DecorationImage(
          alignment: Alignment.topCenter,
          image: ImageUtils.getImageProvider("", holderImg: 'mine/banner'),
          fit: BoxFit.fitWidth,
        ),
      ),
      child: Scaffold(
        backgroundColor: Colors.transparent,
        appBar: MyAppBar(
          isBack: true,
          backImgColor: Colors.white,
          backgroundColor: Colors.transparent,
          centerTitle: '我的资料',
          onPressed: () {},
        ),
        body: Container(
          width: double.infinity,
          height: double.infinity,
          child: Stack(
            children: [
              Positioned(
                left: 0,
                right: 0,
                top: 145.h,
                bottom: 0,
                child: Container(
                  decoration: BoxDecoration(
                    color: Colors.white,
                    borderRadius: BorderRadius.only(topLeft: Radius.circular(40.r), topRight: Radius.circular(40.r)),
                  ),
                ),
              ),
              Container(
                alignment: AlignmentDirectional.topCenter,
                margin: EdgeInsets.only(top: 60.h),
                child: Align(
                  alignment: AlignmentDirectional.topCenter,
                  child: ClipOval(
                    child: Image.network(
                      'https://pic2.zhimg.com/v2-639b49f2f6578eabddc458b84eb3c6a1.jpg',
                      width: 140.w,
                      height: 140.w,
                      fit: BoxFit.cover,
                    ),
                  ),
                ),
              ),
              Positioned(
                left: 0,
                right: 0,
                top: 245.h,
                child: Container(
                  color: Colours.bg_color,
                  child: Column(
                    children: [
                      _FormItemContainer(
                        children: [
                          ..._buildLine("姓名", userInfo!.empName),
                          ..._buildLine("性别", userInfo.empSex == '1' ? '男' : '女', showDivider: false),
                        ],
                      ),
                      SizedBox(height: 10.h),
                      _FormItemContainer(
                        children: [
                          ..._buildLine("部门", userInfo.orgName),
                          ..._buildLine("岗位", userInfo.positionName),
                          ..._buildLine("角色", userInfo.roleName, showDivider: false),
                        ],
                      ),
                      SizedBox(height: 10.h),
                      _FormItemContainer(
                        children: [
                          ..._buildLine("电话", userInfo.empPhone),
                          ..._buildLine("手机", userInfo.empMobile),
                          ..._buildLine("邮箱", userInfo.empEmail, showDivider: false),
                        ],
                      )
                    ],
                  ),
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}

class _FormItemContainer extends StatelessWidget {
  final List<Widget> children;

  _FormItemContainer({required this.children});

  @override
  Widget build(BuildContext context) {
    return Container(
      color: Colors.white,
      padding: EdgeInsets.symmetric(horizontal: 85.w),
      child: Column(
        children: children,
      ),
    );
  }
}
